package PatternOfDesign.Singleton;

/**
 * Created by Ghost on 2015/3/6 0006.
 */
interface Strategy {
    public int operate(int a, int b);

}

interface Operation{
    public int calculate(int a, int b);
}

class AddStrategy implements Strategy{
    @Override
    public int operate(int a, int b) {
        return a+b;
    }
}

class MinusStrategy implements Strategy{

    @Override
    public int operate(int a, int b) {
        return a-b;
    }
}

class Calculator implements Operation{
    private Strategy strategy = null;
    public void setStrategy(String tag){
        if(tag.equals("+")){
            strategy = new AddStrategy();
        }
        if(tag.equals("-")){
            strategy = new MinusStrategy();
        }
    }

    @Override
    public int calculate(int a, int b) {
        return strategy.operate(a,b);
    }
}